/**
 * Copyright 2010 Creative Works, Inc.
 * Creative Works licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package org.sendvox.freswitch.event;

/**
 * The list of events can be found in src/switch_event.c in a char array called
 * EVENT_NAMES and is summarized as follows: <a
 * href="http://wiki.freeswitch.org/wiki/Event_list"
 * >http://wiki.freeswitch.org/wiki/Event_list</a>
 * 
 */
public enum Event {

	SOCKET_DATA("SOCKET_DATA"),		

	/**
	 * Channel Events The channel events can be used to monitor which calls an
	 * extension gets, and in what state the calls currently are. Channel events
	 * can carry additional information for the protocol (i.e. SIP) used to
	 * transport the call. This information can safely be ignored, you don't
	 * have to use it to be able to track calls.
	 */
	CHANNEL_CALLSTATE("CHANNEL_CALLSTATE"),
	/**
	 * Channel create is sent when an extension is going to do something. It can
	 * either be dialing someone or it can be an incoming call to an extension.
	 */
	CHANNEL_CREATE("CHANNEL_CREATE"),
	/**
	 * Called when a channel should get destroyed.
	 */
	CHANNEL_DESTROY("CHANNEL_DESTROY"),
	/**
	 * Sent when a channel has switched its call state. This event does not
	 * contain any additional information.
	 */
	CHANNEL_STATE("CHANNEL_STATE"),
	/**
	 * Someone has answered the call.
	 */
	CHANNEL_ANSWER("CHANNEL_ANSWER"),
	/**
	 * One of the users has hangup. (How do we know which one?)
	 */
	CHANNEL_HANGUP("CHANNEL_HANGUP"),
	/**
	 * Changes has successfully complete the hungup process
	 */
	CHANNEL_HANGUP_COMPLETE("CHANNEL_HANGUP_COMPLETE"),
	/**
	 * This event indicates that the PBX is doing something with the call.
	 * (Typically looking in the dial plan).
	 */
	CHANNEL_EXECUTE("CHANNEL_EXECUTE"),
	/**
	 * Channel has complete its execution
	 */
	CHANNEL_EXECUTE_COMPLETE("CHANNEL_EXECUTE_COMPLETE"),
	/**
	 * A call is being bridged between two endpoints.
	 */
	CHANNEL_BRIDGE("CHANNEL_BRIDGE"),
	/**
	 * A bridge has been terminated. The call itself will most probably be
	 * terminated since bridges exist during a call's lifespan.
	 */
	CHANNEL_UNBRIDGE("CHANNEL_UNBRIDGE"),
	/**
	 * Channel is in progress
	 */
	CHANNEL_PROGRESS("CHANNEL_PROGRESS"),
	/**
	 * Channel media is in progress
	 */
	CHANNEL_PROGRESS_MEDIA("CHANNEL_PROGRESS_MEDIA"),
	/**
	 * An outgoing call is created.
	 */
	CHANNEL_OUTGOING("CHANNEL_OUTGOING"),
	/**
	 * A call is being parked in the PBX.
	 */
	CHANNEL_PARK("CHANNEL_PARK"),
	/**
	 * A call is being unparked.
	 */
	CHANNEL_UNPARK("CHANNEL_UNPARK"),
	/**
	 * This channel event is generated by application='event'
	 */
	CHANNEL_APPLICATION("CHANNEL_APPLICATION"),
	/**
	 * Channel is on hold
	 */
	CHANNEL_HOLD("CHANNEL_HOLD"),
	/**
	 * Channel is in unhold mode
	 */
	CHANNEL_UNHOLD("CHANNEL_UNHOLD"),
	/**
	 * Channel originate events are fired as soon as an originate(or bridge)
	 * completes.
	 */
	CHANNEL_ORIGINATE("CHANNEL_ORIGINATE"),
	/**
	 * his event indicates the Unique-ID of a channel has changed. The original
	 * ID will be reported by Old-Unique-ID. This event will happen when you use
	 * parameter origination_uuid when issuing command originate/bridge.
	 * Example:
	 */
	CHANNEL_UUID("CHANNEL_UUID"),

	// Beginning of -- System events

	/**
	 * Raised when FreeSWITCH started shutdown sequence.
	 */
	SHUTDOWN("SHUTDOWN"),
	/**
	 * Raised when module was load.
	 */
	MODULE_LOAD("MODULE_LOAD"),
	/**
	 * Raised when module was unload.
	 */
	MODULE_UNLOAD("MODULE_UNLOAD"),
	/**
	 * Raised when the xml configuration has been reloaded.
	 */
	RELOADXML("RELOADXML"),
	/**
	 * notify
	 */
	NOTIFY("NOTIFY"),
	/**
	 * send message
	 */
	SEND_MESSAGE("SEND_MESSAGE"),
	/**
	 * receive message
	 */
	RECV_MESSAGE("RECV_MESSAGE"),
	/**
	 * request parameters
	 */
	REQUEST_PARAMS("REQUEST_PARAMS"),
	/**
	 * channel data
	 */
	CHANNEL_DATA("CHANNEL_DATA"),
	/**
	 * general
	 */
	GENERAL("GENERAL"),
	/**
	 * command
	 */
	COMMAND("COMMAND"),
	/**
	 * session heartbeat
	 */
	SESSION_HEARTBEAT("SESSION_HEARTBEAT"),
	/**
	 * client disconnected
	 */
	CLIENT_DISCONNECTED("CLIENT_DISCONNECTED"),
	/**
	 * server disconnected
	 */
	SERVER_DISCONNECTED("SERVER_DISCONNECTED"),
	/**
	 * send info
	 */
	SEND_INFO("SEND_INFO"),
	/**
	 * receive info
	 */
	RECV_INFO("RECV_INFO"),
	/**
	 * call secure
	 */
	CALL_SECURE("CALL_SECURE"),
	/**
	 * nat
	 */
	NAT("NAT"),
	/**
	 * record start
	 */
	RECORD_START("RECORD_START"),
	/**
	 * record stop
	 */
	RECORD_STOP("RECORD_STOP"),
	/**
	 * Received everytime a new playback starts. If multiple files has been set
	 * when calling the playback application, a PLAYBACK_START and PLAYBACK_STOP
	 * event will be received for each file being played.
	 */
	PLAYBACK_START("PLAYBACK_START"),
	/**
	 * See {@code PLAYBACK_START}
	 */
	PLAYBACK_STOP("PLAYBACK_STOP"),
	/**
	 * call update
	 */
	CALL_UPDATE("CALL_UPDATE"),

	// Beginning of -- Other events

	/**
	 * An API function has been invoked. Api command documentation can be found
	 * in the <code>mod_commands</code> section of the FreeSwitch documentation.
	 */
	API("API"),
	/**
	 * Use this to receive an event when a job started with the bgapi call
	 * finishes. The BACKGROUND_JOB event will contain a Job-UUID that matches
	 * up with Job-UUID returned by the server when bgapi is called.
	 */
	BACKGROUND_JOB("BACKGROUND_JOB"),
	/**
	 * Custom is just a place holder for other events. The "Event-Subclass" key
	 * contains which event it is.
	 */
	CUSTOM("CUSTOM"),
	/**
	 * Reschedule a task in the PBX.
	 */
	RE_SCHEDULE("RE_SCHEDULE"),
	/**
	 * Status information for FreeSWITCH triggered by FreeSWITCH's heartbeat
	 * every 20 seconds.
	 */
	HEARTBEAT("HEARTBEAT"),
	/**
	 * Event sent when a tone detected.
	 */
	DETECTED_TONE("DETECTED_TONE"),
	
	PRESENCE_IN("PRESENCE_IN"), 
	
	CODEC("CODEC"), 
	
	MESSAGE_WAITING("MESSAGE_WAITING"), 
	
	PRESENCE_PROBE("PRESENCE_PROBE"), 
	
	MESSAGE_QUERY("MESSAGE_QUERY"),
			
	/**
	 * Will show all events, including custom events. There is no such event
	 * like ALL. This is just like macro when specifying which events to
	 * receive.
	 */
	ALL("ALL");

	private final String literal;

	private Event(String literal) {
		this.literal = literal;
	}

	public String getLiteral() {
		return literal;
	}

	public static Event fromLiteral(String literal) {
		for (Event eventName : values()) {
			if (eventName.literal.equalsIgnoreCase(literal.trim())) {
				return eventName;
			}
		}
		return null;
	}
}
